'use strict';
/** 
 * controllers used for the dashboard
 */
app.controller('SparklineCtrl', ["$scope", function($scope) {
    $scope.sales = [600, 923, 482, 1211, 490, 1125, 1487];
    $scope.earnings = [400, 650, 886, 443, 502, 412, 353];
    $scope.referrals = [4879, 6567, 5022, 5890, 9234, 7128, 4811];
}]);
//incident
app.controller('dashincidentCtrl', ['$scope', '$modal', '$state', '$timeout', 'api_bpm_domain', '$rootScope', 'ngTableParams', '$filter', function($scope, $modal, $state, $timeout, api_bpm_domain, $rootScope, ngTableParams, $filter) {
    var filterData = {
        "assignee": $rootScope.user.id,
        "candidateGroups": $rootScope.user.group[0].id,
        "searchtype": "todo",
        "incident": { "sort": "priority.id", "order": "asc" },
        "idx": 0,
        "sum": 1000
    };
    //获取事件列表
    $scope.reashdata = function() {
        api_bpm_domain.fetchtask("bpm_incident", filterData).then(function(data) {
            // api_bpm_data.fetchDataList('incident', filterData).then(function(data) {
            if (data) {
                $scope.myData = data.data
                    // for (var i = 0; i < $scope.myData.length; i++) {
                    //     $scope.myData[i].acceptDate = moment($scope.myData[i].acceptDate).format('YYYY-MM-DD')
                    // }
            }
        })
    }
    $scope.reashdata();
    $scope.more = function() {
        $state.go('app.incident.list', {})
    }
    $scope.incidentprocess = function(item) {
        $state.go('app.incident.editor', { taskId: item.taskId, processInstanceId: item.processInstanceId });
    }
}]);
//problem
app.controller('dashproblemCtrl', ['$scope', '$modal', '$state', '$timeout', 'api_bpm_domain', '$rootScope', 'ngTableParams', '$filter', function($scope, $modal, $state, $timeout, api_bpm_domain, $rootScope, ngTableParams, $filter) {
    var filterData = {
        "assignee": $rootScope.user.id,
        "candidateGroups": $rootScope.user.group[0].id,
        "searchtype": "todo",
        "problem": { "sort": "priority.id", "order": "asc" },
        "idx": 0,
        "sum": 1000
    };
    $scope.reashdata = function() {
        api_bpm_domain.fetchtask("bpm_problem", filterData).then(function(data) {
            // api_bpm_data.fetchDataList('problem', filterData).then(function(data) {
            if (data) {
                $scope.myData = data.data;
                // for (var i = 0; i < $scope.myData.length; i++) {
                //     $scope.myData[i].acceptDate = moment($scope.myData[i].acceptDate).format('YYYY-MM-DD')
                // }
            }
        })
    }
    $scope.reashdata();
    $scope.more = function() {
        $state.go('app.problem.list', {});
    }
    $scope.problemprocess = function(item) {
        $state.go('app.problem.editor', { taskId: item.taskId, processInstanceId: item.processInstanceId });
    }
}]);
//change
app.controller('dashchangeCtrl', ['$scope', '$modal', '$state', '$timeout', 'api_bpm_domain', '$rootScope', 'ngTableParams', '$filter', function($scope, $modal, $state, $timeout, api_bpm_domain, $rootScope, ngTableParams, $filter) {
    var filterData = {
        "assignee": $rootScope.user.id,
        "candidateGroups": $rootScope.user.group[0].id,
        "searchtype": "todo",
        "idx": 0,
        "sum": 1000
    };
    $scope.reashdata = function() {
        api_bpm_domain.fetchtask("bpm_change", filterData).then(function(data) {
            // api_bpm_data.fetchDataList('change', filterData).then(function(data) {
            if (data) {
                $scope.myData = data.data
                    // for (var i = 0; i < $scope.myData.length; i++) {
                    //     $scope.myData[i].acceptDate = moment($scope.myData[i].acceptDate).format('YYYY-MM-DD')
                    // }
            }
        })
    }
    $scope.reashdata();
    $scope.more = function() {
        $state.go('app.change.list', {});
    }
    $scope.changeprocess = function(item) {
        $state.go('app.change.editor', { taskId: item.taskId, processInstanceId: item.processInstanceId });
    }
}]);
//release
app.controller('dashreleaseCtrl', ['$scope', '$modal', '$state', '$timeout', 'api_bpm_domain', '$rootScope', 'ngTableParams', '$filter', function($scope, $modal, $state, $timeout, api_bpm_domain, $rootScope, ngTableParams, $filter) {
    var filterData = {
        "assignee": $rootScope.user.id,
        "candidateGroups": $rootScope.user.group[0].id,
        "searchtype": "todo",
        "idx": 0,
        "sum": 1000
    };
    $scope.reashdata = function() {
        api_bpm_domain.fetchtask("bpm_release", filterData).then(function(data) {
            // api_bpm_data.fetchDataList('release', filterData).then(function(data) {
            if (data) {
                $scope.myData = data.data;
                // for (var i = 0; i < $scope.myData.length; i++) {
                //     $scope.myData[i].acceptDate = moment($scope.myData[i].acceptDate).format('YYYY-MM-DD')
                // }
            }
        })
    }
    $scope.reashdata();
    $scope.more = function() {
        $state.go('app.release.list', {});
    }
    $scope.releaseprocess = function(item) {
        $state.go('app.release.editor', { taskId: item.taskId, processInstanceId: item.processInstanceId });
    }
}]);
//cmdb
app.controller('dashcmdbCtrl', ['$scope', '$modal', '$state', '$timeout', 'api_bpm_domain', '$rootScope', 'ngTableParams', '$filter', function($scope, $modal, $state, $timeout, api_bpm_domain, $rootScope, ngTableParams, $filter) {
    var filterData = {
        "assignee": $rootScope.user.id,
        "candidateGroups": $rootScope.user.group[0].id,
        "searchtype": "todo",
        "idx": 0,
        "sum": 1000
    };
    $scope.reashdata = function() {
        api_bpm_domain.fetchtask('bpm_configure', filterData).then(function(data) {
            if (data.data) {
                $scope.myData = data.data
                    // for (var i = 0; i < $scope.myData.length; i++) {
                    //     $scope.myData[i].acceptDate = moment($scope.myData[i].acceptDate).format('YYYY-MM-DD')
                    // }
            }
        })
    }
    $scope.reashdata();
    $scope.more = function() {
        $state.go('app.cmdb.plist', {});
    }
    $scope.cmdbprocess = function(item) {
        $state.go('app.cmdb.modeler', { taskId: item.taskId, processInstanceId: item.processInstanceId });
    }
}]);
//knowledge
app.controller('dashknowledgeCtrl', ['$scope', '$modal', '$state', '$timeout', 'api_solution', '$rootScope', 'ngTableParams', '$filter', function($scope, $modal, $state, $timeout, api_solution, $rootScope, ngTableParams, $filter) {
    var filterData = {
        "key": null,
        "userId": $rootScope.user.id,
        "candidateGroups": $rootScope.user.group[0].id,
        "status": 1,
        "pageIndex": 0,
        "pageSum": 1000
    };
    $scope.reashdata = function() {
        api_solution.findSolutionByKeys(filterData).then(function(data) {
            if (data.data) {
                $scope.myData = data.data;
            }
        })
    }
    $scope.reashdata();
    $scope.more = function() {
        $state.go('app.knowledge.manager', {});
    }
    $scope.knowledgeprocess = function(item) {
        $state.go('app.knowledge.manager', {});
    }
}]);
//scheduling
app.controller('dashschedulingCtrl', ["$rootScope", "$scope", "$aside", "$state", "calendarConfig", "moment", "SweetAlert", "Restangular", "api_bpm_schedule", "api_user_data", function($rootScope, $scope, $aside, $state, calendarConfig, moment, SweetAlert, Restangular, api_bpm_schedule, api_user_data) {
    var loginUser = $rootScope.user;
    //console.log(loginUser);
    calendarConfig.dateFormatter = 'moment';
    calendarConfig.i18nStrings.eventsLabel = '排班描述';
    calendarConfig.i18nStrings.timeLabel = '时间';
    calendarConfig.i18nStrings.weekNumber = '{week}周';

    calendarConfig.allDateFormats = {
        angular: {
            date: {
                hour: 'ha',
                day: 'd MMM',
                month: 'MMMM',
                weekDay: 'EEEE',
                time: 'HH:mm',
                datetime: 'MMM d, h:mm a'
            },
            title: {
                day: 'yyyy MMMM EEEE d',
                week: '{year}年第{week}周',
                month: 'yyyy MMMM',
                year: 'yyyy'
            }
        },
        moment: {
            date: {
                hour: 'ha',
                day: 'MMMDD日',
                month: 'MMMM',
                weekDay: 'dddd',
                time: 'HH:mm',
                datetime: 'MMM D, h:mm a'
            },
            title: {
                day: 'YYYY年MMMMDD日, dddd ',
                week: '{year}年第{week}周',
                month: 'YYYY年MMMM',
                year: 'YYYY'
            }
        }
    };

    moment.locale('zh_cn', {
        months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_'),
        monthsShort: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
        weekdays: '星期日_星期一_星期二_星期三_星期四_星期五_星期六'.split('_'),
        weekdaysShort: '周日_周一_周二_周三_周四_周五_周六'.split('_'),
        weekdaysMin: '日_一_二_三_四_五_六'.split('_'),
        longDateFormat: {
            LT: 'Ah点mm分',
            LTS: 'Ah点m分s秒',
            L: 'YYYY-MM-DD',
            LL: 'YYYY年MMMD日',
            LLL: 'YYYY年MMMD日Ah点mm分',
            LLLL: 'YYYY年MMMD日ddddAh点mm分',
            l: 'YYYY-MM-DD',
            ll: 'YYYY年MMMD日',
            lll: 'YYYY年MMMD日Ah点mm分',
            llll: 'YYYY年MMMD日ddddAh点mm分'
        },
        meridiemParse: /凌晨|早上|上午|中午|下午|晚上/,
        meridiemHour: function(hour, meridiem) {
            if (hour === 12) {
                hour = 0;
            }
            if (meridiem === '凌晨' || meridiem === '早上' ||
                meridiem === '上午') {
                return hour;
            } else if (meridiem === '下午' || meridiem === '晚上') {
                return hour + 12;
            } else {
                // '中午'
                return hour >= 11 ? hour : hour + 12;
            }
        },
        meridiem: function(hour, minute, isLower) {
            var hm = hour * 100 + minute;
            if (hm < 600) {
                return '凌晨';
            } else if (hm < 900) {
                return '早上';
            } else if (hm < 1130) {
                return '上午';
            } else if (hm < 1230) {
                return '中午';
            } else if (hm < 1800) {
                return '下午';
            } else {
                return '晚上';
            }
        },
        calendar: {
            sameDay: function() {
                return this.minutes() === 0 ? '[今天]Ah[点整]' : '[今天]LT';
            },
            nextDay: function() {
                return this.minutes() === 0 ? '[明天]Ah[点整]' : '[明天]LT';
            },
            lastDay: function() {
                return this.minutes() === 0 ? '[昨天]Ah[点整]' : '[昨天]LT';
            },
            nextWeek: function() {
                var startOfWeek, prefix;
                startOfWeek = moment().startOf('week');
                prefix = this.unix() - startOfWeek.unix() >= 7 * 24 * 3600 ? '[下]' : '[本]';
                return this.minutes() === 0 ? prefix + 'dddAh点整' : prefix + 'dddAh点mm';
            },
            lastWeek: function() {
                var startOfWeek, prefix;
                startOfWeek = moment().startOf('week');
                prefix = this.unix() < startOfWeek.unix() ? '[上]' : '[本]';
                return this.minutes() === 0 ? prefix + 'dddAh点整' : prefix + 'dddAh点mm';
            },
            sameElse: 'LL'
        },
        ordinalParse: /\d{1,2}(日|月|周)/,
        ordinal: function(number, period) {
            switch (period) {
                case 'd':
                case 'D':
                case 'DDD':
                    return number + '日';
                case 'M':
                    return number + '月';
                case 'w':
                case 'W':
                    return number + '周';
                default:
                    return number;
            }
        },
        relativeTime: {
            future: '%s内',
            past: '%s前',
            s: '几秒',
            m: '1 分钟',
            mm: '%d 分钟',
            h: '1 小时',
            hh: '%d 小时',
            d: '1 天',
            dd: '%d 天',
            M: '1 个月',
            MM: '%d 个月',
            y: '1 年',
            yy: '%d 年'
        },
        week: {
            // GB/T 7408-1994《数据元和交换格式·信息交换·日期和时间表示法》与ISO 8601:1988等效
            dow: 1, // Monday is the first day of the week.
            doy: 4 // The week that contains Jan 4th is the first week of the year.
        }
    });
    //console.log(window.moment().weekdays);

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    console.log(loginUser);
    var filterData = {
        "userId": loginUser.id,
        "startTime": moment(new Date(y, m, 1, 0, 0)).format('YYYY-MM-DD HH:mm:ss'),
        "endTime": moment(new Date(y, m + 1, 1, 0, 0)).format('YYYY-MM-DD HH:mm:ss')
    };
    var load = $scope.load = function(filterData) {
        api_bpm_schedule.fetchSchedule(filterData.userId, filterData.startTime, filterData.endTime).then(function(response) {
            if (response.status == 200) {
                $scope.events = [];
                console.log(response.list);
                var myData = response.list;
                $scope.myschuling = true;
                if (myData.length == 0) {
                    $scope.myschuling = false;
                }
                angular.forEach(myData, function(item) {
                    var eventTemp = {};
                    eventTemp.title = item.description;
                    eventTemp.type = item.scheduleClass.code;
                    eventTemp.startsAt = moment(item['scheduleOrderDTO'].startTime).toDate();
                    eventTemp.endsAtTime = moment(item['scheduleOrderDTO'].endTime).toDate();
                    eventTemp.startTime = item['scheduleOrderDTO'].startTime;
                    eventTemp.endTime = item['scheduleOrderDTO'].endTime;
                    //eventTemp.ends_at = moment(item.endTime).toDate();
                    eventTemp.id = item.id;
                    eventTemp.deletable = false;
                    eventTemp.user = item.user;
                    $scope.events.push(eventTemp);
                })
            }
        });
    }


    $scope.scheduleClass = {};
    var convertEvent = function(scheduleorder) {
        var eventTemp = {};
        eventTemp.title = scheduleorder.description;
        eventTemp.type = scheduleorder.scheduleClass.code;
        eventTemp.startsAt = moment(scheduleorder.startTime).toDate();
        //eventTemp.ends_at = moment(scheduleorder.endTime).toDate();
        eventTemp.id = scheduleorder.id;
        eventTemp.user = scheduleorder.user;
        eventTemp.deletable = false;
        return eventTemp;
    }



    api_bpm_schedule.getScheduleClass().then(function(response) {
        if (response.status == 200) {
            var scheduleClassList = response.list;
            angular.forEach(scheduleClassList, function(item) {
                item.startsAt = moment(item.startTime).format('HH:mm:ss');
                item.endsAt = moment(item.endTime).format('HH:mm:ss');
                // console.log("item.startsAt="+JSON.stringify(item.startsAt))
                // console.log("item.endsAt="+JSON.stringify(item.endsAt))
                $scope.scheduleClass[item['code']] = item;
            })
        }
    })

    $scope.events = [];

    $scope.calendarView = 'month';
    //$scope.calendarDay = new Date();
    $scope.calendarDate = moment().startOf('month').toDate();
    $scope.timeLabel = "时间";
    $scope.eventLabel = "描述";



    function showModal(action, event) {
        // console.log("action="+JSON.stringify(action))
        // var modalInstance = $aside.open({
        //     templateUrl: 'scheduleEvent.html',
        //     placement: 'right',
        //     size: 'sm',
        //     backdrop: true,
        //     controller: function($scope, $modalInstance, scheduleClass, APIService, MementFormat) {
        //         $scope.$modalInstance = $modalInstance;
        //         $scope.action = action;
        //         $scope.event = event;
        //         $scope.scheduleClassic = scheduleClass;
        //         $scope.$watch('event.type', function(newvalue, oldvalue) {
        //             // if(oldvalue == newvalue) return;
        //             // if(scheduleClass[newvalue]){
        //             var sm = MementFormat(scheduleClass[newvalue].startTime);
        //             var em = MementFormat(scheduleClass[newvalue].endTime);
        //             console.log("sm=" + JSON.stringify(sm))
        //             event.starts_at = MementFormat(event.startTime).startOf('day').add(sm.hour(), 'hour').add(sm.minute(), 'minute').add(sm.second(), 'second').toDate();
        //             console.log("event.starts_at=" + JSON.stringify(event.starts_at))
        //             if (sm.hour() > em.hour()) {
        //                 event.ends_at = MementFormat(event.startTime).startOf('day').add(1, 'day').add(em.hour(), 'hour').add(em.minute(), 'minute').add(em.second(), 'second').toDate();
        //                 console.log("event.ends_at=" + JSON.stringify(event.starts_at))
        //             } else {

        //                 event.ends_at = MementFormat(event.startTime).startOf('day').add(em.hour(), 'hour').add(em.minute(), 'minute').add(em.second(), 'second').toDate();
        //                 console.log("event.ends_at=" + JSON.stringify(event.ends_at))
        //             }

        //             // }
        //         });
        //         $scope.cancel = function(event) {
        //             $modalInstance.dismiss();
        //         };
        //         var acUserSelect = $scope.refreshUser = function(key) {

        //             var data = { "idx": "0", "sum": "5" };
        //             if (key) {
        //                 data['user'] = {
        //                     'name': key
        //                 };
        //             }
        //             APIService.fetchDataList('user', data).then(function(response) {
        //                 if (response) {
        //                     if (response.status = 200) {
        //                         $scope.users = response.list;
        //                         console.log($scope.users);
        //                     }
        //                 }
        //             })
        //         };

        //         if (angular.isDefined(event.users) && event.users.length > 0) {

        //         }
        //         $scope.users = [event.user];
        //         acUserSelect();
        //     },
        //     resolve: {
        //         scheduleClass: function() {
        //             return $scope.scheduleClass;
        //         },
        //         APIService: function() {
        //             return api_user_data;
        //         },
        //         MementFormat: function() {
        //             return moment;
        //         }
        //     }
        // });
        // modalInstance.result.then(function(selectedEvent) {
        //     if (selectedEvent.action == 'Clicked') {} else {
        //         //
        //     }
        // });
    }

    $scope.moment = function(string) {
        return moment(string);
    }


    $scope.eventClicked = function(event) {
        // console.log("event="+JSON.stringify(event))
        showModal('Clicked', event);
    };

    $scope.eventEdited = function(event) {
        showModal('Edited', event);
    };


    var updateView = function(newvalue, oldvalue) {
        if (oldvalue == newvalue) return;
        var timeStart, timeEnd, timeStartSpan, timeEndSpan;

        if ($scope.calendarView == "year") {

        } else if ($scope.calendarView == "month") {
            timeStart = moment(newvalue).startOf('month');
            timeEnd = moment(newvalue).endOf('month');
        } else if ($scope.calendarView == "week") {
            timeStart = moment(newvalue).startOf('week');
            timeEnd = moment(newvalue).endOf('week');

        } else if ($scope.calendarView == "Day") {
            timeStart = moment(newvalue).startOf('day');
            timeEnd = moment(newvalue).endOf('day');
        }
        timeStartSpan = timeStart.format('YYYY-MM-DD HH:mm:ss');
        timeEndSpan = timeEnd.format('YYYY-MM-DD HH:mm:ss');
        filterData["startTime"] = timeStartSpan;
        filterData["endTime"] = timeEndSpan;
        load(filterData);
    }

    $scope.$watch('calendarDate', updateView)


    $scope.next = function() {
        $scope.calendarControl.next();
    }

    $scope.prev = function() {
        $scope.calendarControl.prev();
    }

    $scope.setCalendarToToday = function() {
        $scope.calendarDay = new Date();
    };

    $scope.toggle = function($event, field, event) {
        $event.preventDefault();
        $event.stopPropagation();

        event[field] = !event[field];
    };

    $scope.load(filterData);
    $scope.more = function() {
        $state.go('app.scheduling.myscheduling', {});
    }
}]);
app.controller('VisitsCtrl', ["$scope", function($scope) {

    $scope.data = {
        labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        datasets: [{
                label: 'My First dataset',
                fillColor: 'rgba(220,220,220,0.2)',
                strokeColor: 'rgba(220,220,220,1)',
                pointColor: 'rgba(220,220,220,1)',
                pointStrokeColor: '#fff',
                pointHighlightFill: '#fff',
                pointHighlightStroke: 'rgba(220,220,220,1)',
                data: [65, 59, 80, 81, 56, 55, 40, 84, 64, 120, 132, 87]
            },
            {
                label: 'My Second dataset',
                fillColor: 'rgba(151,187,205,0.2)',
                strokeColor: 'rgba(151,187,205,1)',
                pointColor: 'rgba(151,187,205,1)',
                pointStrokeColor: '#fff',
                pointHighlightFill: '#fff',
                pointHighlightStroke: 'rgba(151,187,205,1)',
                data: [28, 48, 40, 19, 86, 27, 90, 102, 123, 145, 60, 161]
            }
        ]
    };

    $scope.options = {

        maintainAspectRatio: false,

        // Sets the chart to be responsive
        responsive: true,

        ///Boolean - Whether grid lines are shown across the chart
        scaleShowGridLines: true,

        //String - Colour of the grid lines
        scaleGridLineColor: 'rgba(0,0,0,.05)',

        //Number - Width of the grid lines
        scaleGridLineWidth: 1,

        //Boolean - Whether the line is curved between points
        bezierCurve: false,

        //Number - Tension of the bezier curve between points
        bezierCurveTension: 0.4,

        //Boolean - Whether to show a dot for each point
        pointDot: true,

        //Number - Radius of each point dot in pixels
        pointDotRadius: 4,

        //Number - Pixel width of point dot stroke
        pointDotStrokeWidth: 1,

        //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
        pointHitDetectionRadius: 20,

        //Boolean - Whether to show a stroke for datasets
        datasetStroke: true,

        //Number - Pixel width of dataset stroke
        datasetStrokeWidth: 2,

        //Boolean - Whether to fill the dataset with a colour
        datasetFill: true,

        // Function - on animation progress
        onAnimationProgress: function() {},

        // Function - on animation complete
        onAnimationComplete: function() {},

        //String - A legend template
        legendTemplate: '<ul class="tc-chart-js-legend"><% for (var i=0; i<datasets.length; i++){%><li><span style="background-color:<%=datasets[i].strokeColor%>"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>'
    };

}]);
app.controller('SalesCtrl', ["$scope", function($scope) {

    // Chart.js Data
    $scope.data = {
        labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
        datasets: [{
                label: 'My First dataset',
                fillColor: 'rgba(220,220,220,0.5)',
                strokeColor: 'rgba(220,220,220,0.8)',
                highlightFill: 'rgba(220,220,220,0.75)',
                highlightStroke: 'rgba(220,220,220,1)',
                data: [65, 59, 80, 81, 56, 55, 40]
            },
            {
                label: 'My Second dataset',
                fillColor: 'rgba(151,187,205,0.5)',
                strokeColor: 'rgba(151,187,205,0.8)',
                highlightFill: 'rgba(151,187,205,0.75)',
                highlightStroke: 'rgba(151,187,205,1)',
                data: [28, 48, 40, 19, 86, 27, 90]
            }
        ]
    };

    // Chart.js Options
    $scope.options = {
        maintainAspectRatio: false,

        // Sets the chart to be responsive
        responsive: true,

        //Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
        scaleBeginAtZero: true,

        //Boolean - Whether grid lines are shown across the chart
        scaleShowGridLines: true,

        //String - Colour of the grid lines
        scaleGridLineColor: "rgba(0,0,0,.05)",

        //Number - Width of the grid lines
        scaleGridLineWidth: 1,

        //Boolean - If there is a stroke on each bar
        barShowStroke: true,

        //Number - Pixel width of the bar stroke
        barStrokeWidth: 2,

        //Number - Spacing between each of the X value sets
        barValueSpacing: 5,

        //Number - Spacing between data sets within X values
        barDatasetSpacing: 1,

        //String - A legend template
        legendTemplate: '<ul class="tc-chart-js-legend"><% for (var i=0; i<datasets.length; i++){%><li><span style="background-color:<%=datasets[i].fillColor%>"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>'
    };

}]);
app.controller('OnotherCtrl', ["$scope", function($scope) {

    // Chart.js Data
    $scope.data = [{
            value: 300,
            color: '#F7464A',
            highlight: '#FF5A5E',
            label: 'Red'
        },
        {
            value: 50,
            color: '#46BFBD',
            highlight: '#5AD3D1',
            label: 'Green'
        },
        {
            value: 100,
            color: '#FDB45C',
            highlight: '#FFC870',
            label: 'Yellow'
        }
    ];
    $scope.total = 450;
    // Chart.js Options
    $scope.options = {

        // Sets the chart to be responsive
        responsive: false,

        //Boolean - Whether we should show a stroke on each segment
        segmentShowStroke: true,

        //String - The colour of each segment stroke
        segmentStrokeColor: '#fff',

        //Number - The width of each segment stroke
        segmentStrokeWidth: 2,

        //Number - The percentage of the chart that we cut out of the middle
        percentageInnerCutout: 50, // This is 0 for Pie charts

        //Number - Amount of animation steps
        animationSteps: 100,

        //String - Animation easing effect
        animationEasing: 'easeOutBounce',

        //Boolean - Whether we animate the rotation of the Doughnut
        animateRotate: true,

        //Boolean - Whether we animate scaling the Doughnut from the centre
        animateScale: false,

        //String - A legend template
        legendTemplate: '<ul class="tc-chart-js-legend"><% for (var i=0; i<segments.length; i++){%><li><span style="background-color:<%=segments[i].fillColor%>"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>'

    };

}]);
app.controller('LastCtrl', ["$scope", function($scope) {

    // Chart.js Data
    $scope.data = {
        labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
        datasets: [{
                label: 'My First dataset',
                fillColor: 'rgba(220,220,220,0.2)',
                strokeColor: 'rgba(220,220,220,1)',
                pointColor: 'rgba(220,220,220,1)',
                pointStrokeColor: '#fff',
                pointHighlightFill: '#fff',
                pointHighlightStroke: 'rgba(220,220,220,1)',
                data: [65, 59, 90, 81, 56, 55, 40]
            },
            {
                label: 'My Second dataset',
                fillColor: 'rgba(151,187,205,0.2)',
                strokeColor: 'rgba(151,187,205,1)',
                pointColor: 'rgba(151,187,205,1)',
                pointStrokeColor: '#fff',
                pointHighlightFill: '#fff',
                pointHighlightStroke: 'rgba(151,187,205,1)',
                data: [28, 48, 40, 19, 96, 27, 100]
            }
        ]
    };

    // Chart.js Options
    $scope.options = {

        // Sets the chart to be responsive
        responsive: true,

        //Boolean - Whether to show lines for each scale point
        scaleShowLine: true,

        //Boolean - Whether we show the angle lines out of the radar
        angleShowLineOut: true,

        //Boolean - Whether to show labels on the scale
        scaleShowLabels: false,

        // Boolean - Whether the scale should begin at zero
        scaleBeginAtZero: true,

        //String - Colour of the angle line
        angleLineColor: 'rgba(0,0,0,.1)',

        //Number - Pixel width of the angle line
        angleLineWidth: 1,

        //String - Point label font declaration
        pointLabelFontFamily: '"Arial"',

        //String - Point label font weight
        pointLabelFontStyle: 'normal',

        //Number - Point label font size in pixels
        pointLabelFontSize: 10,

        //String - Point label font colour
        pointLabelFontColor: '#666',

        //Boolean - Whether to show a dot for each point
        pointDot: true,

        //Number - Radius of each point dot in pixels
        pointDotRadius: 3,

        //Number - Pixel width of point dot stroke
        pointDotStrokeWidth: 1,

        //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
        pointHitDetectionRadius: 20,

        //Boolean - Whether to show a stroke for datasets
        datasetStroke: true,

        //Number - Pixel width of dataset stroke
        datasetStrokeWidth: 2,

        //Boolean - Whether to fill the dataset with a colour
        datasetFill: true,

        //String - A legend template
        legendTemplate: '<ul class="tc-chart-js-legend"><% for (var i=0; i<datasets.length; i++){%><li><span style="background-color:<%=datasets[i].strokeColor%>"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>'
    };

}]);